Expand description

A Rust source code formatting crate with a unified interface for string, file, and TokenStream input. It currently supports rustfmt and prettyplease.

use rust_format::{Formatter, RustFmt};

let source = r#"fn main() { println!("Hello World!"); }"#;

let actual = RustFmt::default().format_str(source).unwrap();
let expected = r#"fn main() {
    println!("Hello World!");
}
"#;

assert_eq!(expected, actual);

Macros

_blank_post_process

A “marker” macro used to mark locations in the source code where blank lines should be inserted. If no parameter is given, one blank line is assumed, otherwise the integer literal specified gives the # of blank lines to insert.

_comment_post_process

A “marker” macro used to mark locations in the source code where comments should be inserted. If no parameter is given, a single blank comment is assumed, otherwise the string literal specified is broken into lines and those comments will be inserted individually.

Structs

The configuration for the formatters. Most of the options are for rustfmt only (they are ignored by PrettyPlease, but PostProcess options are used by both formatters).

PrettyPleasepretty_please

This formatter uses prettyplease for formatting source code

This formatter uses rustfmt for formatting source code

Enums

The Rust edition the source code uses

This error is returned when errors are triggered during the formatting process

Post format processing options - optionally replace comment/blank markers and doc blocks

Traits

A unified interface to all formatters. It allows for formatting from string, file, or TokenStream